<?php

namespace App\Admin\Controllers;

use App\Models\User;
use App\Models\UserLog;
use Encore\Admin\Controllers\AdminController;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Show;

class UserLogController extends AdminController
{
    /**
     * Title for current resource.
     *
     * @var string
     */
    protected $title = '明细查询';

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        $grid = new Grid(new UserLog());

        $grid->column('id', __('Id'))->sortable();
        $grid->column('user.username', __('用户'))->sortable();
        $grid->column('currency_type', __('类型'))->sortable();
        $grid->column('type', __('操作类型'))->sortable();
        $grid->column('in', __('进账'))->sortable();
        $grid->column('out', __('出账'))->sortable();
        $grid->column('end', __('剩余'))->sortable();
        $grid->column('remark', __('备注'))->sortable();
        $grid->column('status', __('状态'))->display(function ($status) {
            return config('conf.status')[$status];
        })->sortable();
        $grid->column('created_at', __('创建时间'))->sortable();
        $grid->disableCreateButton();
        $grid->disableActions();
        $grid->column('id', 'ID')->sortable()->totalRow('合计');
        $grid->column('in', '进账')->totalRow();
        $grid->column('out', '出账')->totalRow();
        $grid->filter(function($filter){

            // 去掉默认的id过滤器
            $filter->disableIdFilter();
           // $filter->equal('currency_type','类型')->select(['balance' => '余额','btc'=>'比特币','electricity_fee'=>'电费']);
            $filter->equal('type','操作类型')->select(config('conf.user_log'));
            $filter->between('created_at', '时间')->datetime();
            $users = User::all()->toArray();
            $users = array_column($users,'username','id');
            $filter->equal('user_id','用户名')->select($users);

        });
        return $grid;
    }

}
